package it.rap.application.logic.mappers;

import it.rap.application.logic.BusinnessLogic;
import it.rap.applications.persistence.entities.contoCorrente.ContoCorrente;
import it.rap.applications.persistence.entities.movimento.Movimento;
import it.rap.applications.persistence.entities.movimento.Saldo;

import java.math.BigDecimal;
import java.util.List;

import javax.persistence.Parameter;
import javax.persistence.Query;

public class ContoCorrenteLogic extends BusinnessLogic {

	public ContoCorrenteLogic() {
		super("publisher");
	}

	public void persist(ContoCorrente m) {
		enm.persist(m);
	}

	public List<ContoCorrente> selectAll(Integer currentDataOffset,	Integer currentDataLimit) {
		StringBuffer q = new StringBuffer();
		q.append( " SELECT c ");
		q.append( " FROM  ContoCorrente c" );
		Query query = enm.createQuery( q.toString() );
		query.setFirstResult( currentDataOffset ).setMaxResults( currentDataLimit );
		List<ContoCorrente> mList = (List<ContoCorrente>)query.getResultList();
		return mList;
	}

	public ContoCorrente getContoCorrenteByFinder(ContoCorrente cc) {
		StringBuffer q = new StringBuffer();
		q.append( " SELECT c ");
		q.append( " FROM  ContoCorrente c" );
		q.append( " WHERE  1=1 " );
		if ( cc.getState() != null ){
			q.append( " AND   c.state = :state");
		}
		Query query = enm.createQuery( q.toString() );
		if ( cc.getState() != null ){
			query.setParameter("state", cc.getState());
		}
		ContoCorrente _cc = (ContoCorrente)query.getSingleResult();
		return _cc;
	}

}
